<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    let rows = prompt("请输入打印金字塔的层级");
    let str = "";
    for (let r = 1;r <= rows;r ++) {
        // 先循环空格次数
        for (let j = 0;j < rows - r;j ++) {
            str += ' ';
        }

        // 循环*的次数
        for (let j = 0;j < 2 * r - 1;j ++) {
            str += '*';
        }
        // 换行 \n表示换行符
        str += '\n';
    }
    console.log(str);

</script>
</html>